package cn.com.infcn.spider.scheduler.data;

import java.util.HashMap;
import java.util.Map;

import org.nlpcn.commons.lang.util.StringUtil;

import com.alibaba.fastjson.JSONObject;

import cn.com.infcn.spider.domain.Doc;
import cn.com.infcn.spider.domain.Job;
import cn.com.infcn.spider.domain.Record;
import cn.com.infcn.spider.scheduler.SimpleScheduler;
import cn.com.infcn.spider.util.JythonRunner;

/**
 * 具有迭代要求的jdbc,目录迁移
 * 
 * @author ansj
 *
 */
public class DataScheduler extends SimpleScheduler {

	public DataScheduler(Job job) {
		super(job);
	}

	@Override
	protected Doc innerExplain(Object obj) {
		Record record = new Record();
		if (StringUtil.isNotBlank(job.getParse())) {
			record.setResult((JSONObject) JSONObject.toJSON(obj));
			Map<String, Object> map = new HashMap<>();
			map.put("_result", record.getResult());
			map.put("_doc", record);
			JythonRunner.run(map, job.getParse());
		}
		return record;
	}

}
